#! usr/bin/env perl
# author: maxiao
# date: 2023-03-09 15:08
# description: 猜数游戏

use v5.20;
use strict;
use warnings;
use utf8;

binmode STDIN, ':encoding(UTF-8)';
binmode STDOUT, ':encoding(UTF-8)';

# 产生1至100的随机数
my $random_num = int( 1 + rand 100 );
print $random_num, "\n";
my $num = 1;
while (1) {
    chomp(my $input = <STDIN>);
    if ( $input =~ /exit|quit|^\s+$/ ) {
        print "You gave up! The secrtes is $random_num\n";
        last;
    } elsif ( $input > $random_num ) {
        print "Too larger\n";
    } elsif ( $input == $random_num ) {
        print "Pass \n";
        last;
    } else {
        print "Too smaller\n";
    }
    $num ++;
}
print "\n您总共尝试了${num}次!\n";
